import { AccessLevel, SingletonProto } from "@eggjs/tegg";
import { HttpException, Success } from "@/core/HttpException";

/**
 * web层通用数据处理
 * 
 * @author JN
 */
@SingletonProto({
    accessLevel: AccessLevel.PUBLIC
})
export class BaseController {

    /**
     * 返回成功消息
     */
    success(msg?: any) {
        return msg ? new Success(msg) : new Success()
    }

    /**
     * 返回失败消息
     */
    error(msg?: any) {
        return msg ? new HttpException(msg) : new HttpException()
    }

    /**
     * 响应返回结果
     * 
     * @param rows 影响行数
     * @return 操作结果
     */
    toAjax(rows: number | boolean) {
        return Number(rows) > 0 ? new Success() : new HttpException();
    }
}